package com.gmall.java;

import java.util.function.*;

interface MyInterface{
    void show(String a);
}
public class FuctionInterfaceTest2 {

    public static void main(String[] args) {

        //1.1 Function 有1个输入，1个输出
        Function<Integer,String> function = a -> "2203A====" + a;
        System.out.println(function.apply(100));
        //1.2 BiFunction 有2个输入，1个输出
        BiFunction<Integer,Float,String> add = (a,b)->{
            return String.valueOf(a+b)+"====";
        };
        String sum = add.apply(10, 5.9F);
        System.out.println(sum);

        //2.1 Consumer 有1个输入，没有输出
        //2.2 BiConsumer 有2个输入，没有输出
        Consumer<String> consumer = (a)->{
            System.out.println(a);
        };
        consumer.accept("123456");

        BiConsumer<String,String> biConsumer=(a,b)->{
            System.out.println(a+"----" + b);
        };
        biConsumer.accept("张","三");

        //3.1 没有输入，有1个输出
        Supplier<String> supplier = ()->{
            return "hello";
        };
        System.out.println(supplier.get());

        //4.1 Predicate 断言，判断, 有一个输入，返回boolean
        //4.2 BiPredicate 断言，判断，有两个输入，返回boolean
        Predicate<Integer> predicate = (integer)->{return integer>5;};
        boolean test = predicate.test(1);
        System.out.println(test);

        BiPredicate<Integer,Integer> biPredicate = (a,b)->{return a>b;};
        System.out.println(biPredicate.test(10,15));


        //example
        Supplier<Integer> a =()->{
            Integer sum1 =0;
            for(int i=1;i<=100;i++){
                sum1+=i;
            }
            return sum1;
        };

        System.out.println(a.get());

    }
}
